package cn.itcast.ssm.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.itcast.ssm.po.ItemsCustom;
import cn.itcast.ssm.service.ItemsService;

@Controller
// 为了对url进行分类管理 ，可以在这里定义根路径，最终访问url是根路径+子路径
// 比如：商品列表：/items/queryItems.action
@RequestMapping("/items")
public class ItemsController {
	@Autowired
	private ItemsService itemsService;
	
	@RequestMapping("/queryItems")
	public ModelAndView queryItems() {
		System.out.println("jfajppp222p");
		List<ItemsCustom> itemsList = itemsService.findItemsList(null);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("itemsList", itemsList);
		modelAndView.setViewName("items/itemsList");
		return modelAndView;
	}

	@RequestMapping("/queryItem")
	public ModelAndView queryItem() {
		System.out.println("jfajppp222p");
		List<ItemsCustom> itemsList = itemsService.findItemsList(null);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("itemsList", itemsList);
		modelAndView.setViewName("items/itemsList");
		return modelAndView;
	}

	@RequestMapping("/editItems")
	public String editItems(Model model,Integer id) {
		System.out.println("ididii");
		System.out.println("id="+id);
		ItemsCustom itemsCustom = itemsService.findItemsById(id);
		model.addAttribute("itemsCustom", itemsCustom);
		return "items/editItems";
	}
	@RequestMapping("/findtest")
	public void findtest(){
		System.out.println("fadadssss111sdfsd");
	}
	@RequestMapping("/editItemsSubmit")
	public String editItemsSubmit(ItemsCustom itemsCustom,Integer id){
		System.out.println(id);
		itemsService.updateItems(id, itemsCustom);
//		return "forward:queryItems.action";
		return "redirect:queryItems.action";
	}
	@RequestMapping("/editIit1")
	public String editItemsSubmit1(ItemsCustom itemsCustom,Integer id){
		System.out.println(id);
		itemsService.updateItems(id, itemsCustom);
//		return "forward:queryItems.action";
		return "redirect:queryItems.action";
	}
}


